/*
 * CiselnikRenderer.java
 *
 * Created on 21. listopad 2006, 19:28
 *
 */

package cz.results.winter6.view.browse.table;

import cz.results.winter6.model.Ciselnik;
import java.awt.Component;
import java.util.Iterator;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class CiselnikTableCellRenderer extends JComboBox implements TableCellRenderer {
    
    private Ciselnik ciselnik;
    
    public CiselnikTableCellRenderer(Ciselnik ciselnik) {
        super();
        this.setCiselnik(ciselnik);
        naplnHodnoty();
        
    }
    
    private void naplnHodnoty(){
        for(Iterator i=ciselnik.iterator();i.hasNext();) {
            String hodnota = (String) i.next();
            addItem(hodnota);
        }
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 
            boolean hasFocus, int row, int col) {
        
        if(isSelected){
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }
        
        setSelectedItem((String)value);
        return this;
    }
    
    
    public Ciselnik getCiselnik() {
        return ciselnik;
    }

    public void setCiselnik(Ciselnik ciselnik) {
        this.ciselnik = ciselnik;
    }
    
}
